<?php
class EventProductForm extends Form{
	function EventProductForm(){
		Form::Form('EventProductForm');
		CGlobal::$website_title='Quản lý sản phẩm sự kiện';
		
		$this->link_css('style/manage_item.css');
		
		$this->link_css('style/aznet/ui.datepicker.css');
		$this->link_js('javascript/jquery/ui.datepicker.js');
	}

	function draw(){
		global $display;
		$this->beginForm();
		
		$where='';
		
		$page		=	Url::get('page',1);
		$e_id		=	Url::get('e_id',0);
		
		$user_name	=	Url::get('user_name');
		$status		=	Url::get('status',0);
		
		if($user_name){
			$where.=($where!=''?' AND ':'WHERE ')." user_name = '$user_name'";
		}
		
		if($e_id){
			$where.=($where!=''?' AND ':'WHERE ')." id = $e_id";
		}
		
		if($status==4){
			$where.=($where!=''?' AND ':'WHERE ')." status = 0";
		}
		elseif($status)
		{
			$where.=($where!=''?' AND ':'WHERE ')." status = $status";
		}
		
		$date_start = Url::get('date_start');
		$date_end 	= Url::get('date_end');
		
		if($date_start){
			$arr = explode('-',$date_start);
			$where.=($where!=''?' AND ':'WHERE ')." time>=".mktime(0,0,0,$arr[1],$arr[0],$arr[2]);
		}
		
		if($date_end){
			$arr = explode('-',$date_end);
			$where.=($where!=''?' AND ':'WHERE ')." time<=".mktime(23,59,59,$arr[1],$arr[0],$arr[2]);
		}
		
		$display ->add('e_id',	$e_id);
		$display ->add('date_start',	$date_start);
		$display ->add('date_end',	$date_end);
		$display ->add('user_name',	$user_name);
		$display ->add('status',		$status);
		
		$display ->add('url', Url::build_all(array('cmd')));
		
		$total = DB::fetch("SELECT COUNT(*) AS total_row FROM event_product $where",'total_row',0);
		
		$display ->add('total',	$total);
		
		$pagging	='';
		$items=array();
		$sms_rows=array();
		$item_ids='';
		
		if($total){
			//----- Pagging ---------------
			$limit 			= '';
			$pagging      	= AZPagging::pagingSE($limit,$total,50,10,'page_no',true,' SMS');
			//----- Pagging ---------------
			
			$sql="SELECT * FROM event_product $where ORDER BY id DESC $limit";
				
			$re=DB::query($sql);
			
			if($re)
			{
				while($sms_row = mysql_fetch_assoc($re))
				{	
					$sms_row['time_c'] 	= 	"Tạo: ".date('H\hi d.m.Y',$sms_row['time_c'])." bởi {$sms_row['user_c']}";
					$sms_row['time_m'] 	= 	"Tạo: ".date('H\hi d.m.Y',$sms_row['time_m'])." bởi {$sms_row['user_m']}";
					
					
					if($sms_row['img_url'] !='' && isset(CGlobal::$img_server[$sms_row['img_server']]))
					{
						$sms_row['img'] 	= 	"<a href='http://".CGlobal::$img_server[$sms_row['img_server']]."/{$sms_row['img_url']}' target='_blank'>Img</a>";
					}
					
					if($sms_row['status']==4)
					{
						$sms_row['status'] = "<font color='#cc0000'>Đã xoá</font> (lúc ".date('H\hi d.m.Y',$sms_row['time_c'])." bởi {$sms_row['user_c']})";
					}
					elseif ($sms_row['status']==1)
					{
						$sms_row['status'] = '<font color="green">OK</font>';		
					}
					elseif ($sms_row['status']==2)
					{
						$sms_row['status'] = '<font color="brown">Disable</font>';		
					}
					elseif ($sms_row['status']==3)
					{
						$sms_row['status'] = '<font color="blue">Finished</font>';		
					}
						
					//$sms_row['note'] = ($sms_row['note']!=''?"<b>{$sms_row['user_m']} (".date("H\h:i d/m/Y",$sms_row['m_time']).")</b>":"")." ".stripslashes($sms_row['note']).'<br /><img style="cursor:pointer" alt="Ghi chú" title="Ghi chú" src="style/images/action_reply.gif" onclick="note_ua_sms(\''.$sms_row['id'].'\',\''.AZLib::remove_4_js($sms_row['note']).'\');" /> ';
				
					$sms_row['edit_link'] 	= "evnent.html?cmd=edit&id={$sms_row['id']}";
					$sms_row['del_link'] 	= "evnent.html?cmd=del&id={$sms_row['id']}";
					
					$sms_rows[$sms_row['id']] = $sms_row;															
				}
			}
		}
		
		$display ->add('is_root',User::is_root());
		$display ->add('items',$sms_rows);
		$display ->add('pagging',$pagging);
		
		$display ->output('e_product');
		$this->endForm();
	}
}
?>